package module.main.view.mainInterface.playerresourcepanel
{
	
	import code.ui.SimpleToolTips;
	
	import com.darwin.darwinUI.containers.ContainerBase;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.manager.ToolTipManager;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.events.MouseEvent;
	
	import module.main.MainConfig;
	import module.main.MainConst;
	import module.main.view.MainView;
	import module.main.view.ResourceConst;


	public class ResourceInformationPanel extends ContainerBase
	{
		private var _nameArray:Array;
		private var _goldItem:GoldItem;
		private var _array:Array = new Array();
		private var uicommand:UIComponent;
		public function ResourceInformationPanel()
		{
			uicommand = new UIComponent;
			_goldItem = new GoldItem();
			_nameArray = [ResourceConst.RESOURCEINFO_FOOD_ICON,ResourceConst.RESOURCEINFO_STONE_ICON,ResourceConst.RESOURCEINFO_WOOD_ICON,ResourceConst.RESOURCEINFO_IRON_ICON]
			trace(_nameArray);
			addItem(uicommand);
			initList();
		}
		public function updataFoodInfo():void
		{
			if(MainView.getInstance().playerObj)
			{
			var _resourceNumStr:String;
			for(var j:uint = 0;j<_array.length;j++)
			{
				if(_nameArray[j] == ResourceConst.RESOURCEINFO_IRON_ICON)
				{
					_resourceNumStr = "steel";
				}
				if(_nameArray[j] == ResourceConst.RESOURCEINFO_STONE_ICON)
				{
					_resourceNumStr = "stone";
				}
				if(_nameArray[j] == ResourceConst.RESOURCEINFO_WOOD_ICON)
				{
					_resourceNumStr = "tree";
				}
				if(_nameArray[j] == ResourceConst.RESOURCEINFO_FOOD_ICON)
				{
					_resourceNumStr = "food";
				}
				if(MainView.getInstance().playerObj&&_resourceNumStr)
				{
					if(_resourceNumStr == "food")
					{
						_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.food.toString();
					}
					else
					{
						if(_resourceNumStr == "tree")
						{
							_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.wood.toString();
						}
						if(_resourceNumStr == "stone")
						{
							_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.stone.toString();
						}
						if(_resourceNumStr == "steel")
						{
							_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.iron.toString();
						}
					}
				}
			}
			}
		}
		/**
		 *金币刷新 
		 * 
		 */		
		public function updataGoldInfo():void
		{
			if(MainView.getInstance().playerObj)
			{
				_goldItem.goldNumTxt.text = MainView.getInstance().playerObj["gold"].toString();
			}
		}
		public function updataResouseInfo():void
		{
			if(MainView.getInstance().playerObj)
			{
				_goldItem.goldNumTxt.text = MainView.getInstance().playerObj["gold"].toString();
				var _resourceNumStr:String;
				for(var j:uint = 0;j<_array.length;j++)
				{
					if(_nameArray[j] == ResourceConst.RESOURCEINFO_IRON_ICON)
					{
						_resourceNumStr = "steel";
					}
					if(_nameArray[j] == ResourceConst.RESOURCEINFO_STONE_ICON)
					{
						_resourceNumStr = "stone";
					}
					if(_nameArray[j] == ResourceConst.RESOURCEINFO_WOOD_ICON)
					{
						_resourceNumStr = "tree";
					}
					if(_nameArray[j] == ResourceConst.RESOURCEINFO_FOOD_ICON)
					{
						_resourceNumStr = "food";
					}
					if(MainView.getInstance().playerObj&&_resourceNumStr)
					{
						if(_resourceNumStr == "food")
						{
							_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.food.toString();
						}
						else
						{
							if(_resourceNumStr == "tree")
							{
								_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.wood.toString();
							}
							if(_resourceNumStr == "stone")
							{
								_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.stone.toString();
							}
							if(_resourceNumStr == "steel")
							{
								_array[j].resourceNumTxt.text = MainView.getInstance().playerObj.iron.toString();
							}
						}
				}
			}
		}
		}
		private function initList():void
		{
			var num:Number;
			var width:Number;
			for(var i:uint = 0;i<4;i++)
			{
				var produceItemList:ResourceInformationItem = new ResourceInformationItem(_nameArray[i]);
				_array.push(produceItemList);
				produceItemList.x = i *　produceItemList.width - 6 * i;
				if(i == 3)
				{
					num = produceItemList.x;
					width = produceItemList.width;
				}
				uicommand.addChild(produceItemList);
				produceItemList.addEventListener(MouseEvent.MOUSE_OVER,mousemoveHandler);
				produceItemList.mouseChildren = false;
			}
			_goldItem.x = num + width + 80;
			uicommand.addChild(_goldItem);
			this.width = width * 4 + _goldItem.width + 80;
		}
		private function mousemoveHandler(e:MouseEvent):void
		{
			if(MainView.getInstance().playerObj)
			{
				switch(e.target)
				{
					case _array[0]:
						UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"食物<br>" + MainView.getInstance().playerObj.food + " / " +MainConfig.getResourceLimit(MainView.getInstance().playerObj.landLevel,MainConst.FOOD) ,ToolTipManager.DOWN);
						break;
					case _array[1]:
						UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"石材<br>" + MainView.getInstance().playerObj.stone  + " / " +MainConfig.getResourceLimit(MainView.getInstance().playerObj.landLevel,MainConst.STONE),ToolTipManager.DOWN);
						break;
					case _array[2]:
						UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"木材<br>" + MainView.getInstance().playerObj.wood  + " / " +MainConfig.getResourceLimit(MainView.getInstance().playerObj.landLevel,MainConst.WOOD),ToolTipManager.DOWN);
						break;
					case _array[3]:
						UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"铁矿<br>" + MainView.getInstance().playerObj.iron  + " / " +MainConfig.getResourceLimit(MainView.getInstance().playerObj.landLevel,MainConst.IRON),ToolTipManager.DOWN);
						break;
					default:
						break;
				}
			}
		}
	}
}